package com.nxj.service.impl;

import com.nxj.annotation.Autowired;
import com.nxj.annotation.Service;
import com.nxj.annotation.Transactional;
import com.nxj.dao.TransferDao;
import com.nxj.pojo.Account;
import com.nxj.service.TransferService;

@Service
@Transactional
public class TransferServiceImpl implements TransferService {

    //TransferDao transferDao = (TransferDao) IOCFactory.getBean("transferDao");

    @Autowired
    TransferDao transferDaoImpl;

    /*
    public void setTransferDao(TransferDao transferDao) {
        this.transferDao = transferDao;
    }
    */

    @Override
    public void trans(String fromNo, String toNo, String money) throws Exception {
        Account fromMoney = transferDaoImpl.queryCardNo(fromNo);
        Account toMoney = transferDaoImpl.queryCardNo(toNo);

        fromMoney.setMoney(fromMoney.getMoney() - Integer.valueOf(money));
        toMoney.setMoney(toMoney.getMoney() + Integer.valueOf(money));

        transferDaoImpl.updateCardNo(toMoney);
        //int ccc = 1 / 0;
        transferDaoImpl.updateCardNo(fromMoney);

        System.out.println("transfer service end and result： ");
    }
}
